|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Admin.java | 50% | 65.6% | 66.7% | 64.3% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* $Id: Admin.java,v 1.1 2004/12/15 14:18:08 patforna Exp $
|
|
| 3 |
*
|
|
| 4 |
* Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
|
|
| 5 |
* Berne University of Applied Sciences
|
|
| 6 |
* School of Engineering and Information Technology
|
|
| 7 |
* All rights reserved.
|
|
| 8 |
*/
|
|
| 9 |
package bexee.admin;
|
|
| 10 |
|
|
| 11 |
import java.io.ByteArrayOutputStream;
|
|
| 12 |
import java.io.File;
|
|
| 13 |
import java.io.FileInputStream;
|
|
| 14 |
import java.io.FileNotFoundException;
|
|
| 15 |
import java.io.IOException;
|
|
| 16 |
import java.io.InputStream;
|
|
| 17 |
import java.rmi.RemoteException;
|
|
| 18 |
import java.util.ArrayList;
|
|
| 19 |
import java.util.Iterator;
|
|
| 20 |
import java.util.List;
|
|
| 21 |
|
|
| 22 |
import javax.xml.rpc.ParameterMode;
|
|
| 23 |
import javax.xml.rpc.ServiceException;
|
|
| 24 |
|
|
| 25 |
import org.apache.axis.client.Call;
|
|
| 26 |
import org.apache.axis.client.Service;
|
|
| 27 |
import org.apache.axis.encoding.XMLType;
|
|
| 28 |
import org.apache.commons.io.CopyUtils;
|
|
| 29 |
import org.apache.commons.logging.Log;
|
|
| 30 |
import org.apache.commons.logging.LogFactory;
|
|
| 31 |
|
|
| 32 |
import bexee.util.BexeeProperties;
|
|
| 33 |
import bexee.util.Constants;
|
|
| 34 |
|
|
| 35 |
/**
|
|
| 36 |
* This class acts as a convenient Java front-end for the
|
|
| 37 |
* {@link bexee.admin.Manager}class instead of calling the <code>Manager</code>
|
|
| 38 |
* web service directly.
|
|
| 39 |
*
|
|
| 40 |
* @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:08 $
|
|
| 41 |
* @author Patric Fornasier
|
|
| 42 |
* @author Pawel Kowalski
|
|
| 43 |
*/
|
|
| 44 |
public class Admin { |
|
| 45 |
|
|
| 46 |
private static Log log = LogFactory.getLog(Admin.class); |
|
| 47 |
|
|
| 48 |
private String url;
|
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Create an instance of the <code>Admin</code>
|
|
| 52 |
*
|
|
| 53 |
*/
|
|
| 54 | 4 |
public Admin() {
|
| 55 | 4 |
this.url = BexeeProperties.getProperty(Constants.OPT_MANAGER_URL,
|
| 56 |
Constants.OPT_MANAGER_URL_DEF); |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/**
|
|
| 60 |
* Create an instance of the <code>Admin</code> with a give
|
|
| 61 |
* <code>URL</code> where bexee is located.
|
|
| 62 |
*
|
|
| 63 |
* @param url
|
|
| 64 |
* bexee location
|
|
| 65 |
*/
|
|
| 66 | 0 |
public Admin(String url) {
|
| 67 | 0 |
this.url = url;
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
/**
|
|
| 71 |
* Deploy a BPEL business process together with its WSDL.
|
|
| 72 |
*
|
|
| 73 |
* @param bpel
|
|
| 74 |
* BPEL document
|
|
| 75 |
* @param wsdl
|
|
| 76 |
* WSDL description
|
|
| 77 |
* @return @throws
|
|
| 78 |
* AdminException
|
|
| 79 |
*/
|
|
| 80 | 0 |
public String deploy(File bpel, File wsdl) throws AdminException { |
| 81 | 0 |
return deploy(bpel, wsdl, new ArrayList()); |
| 82 |
} |
|
| 83 |
|
|
| 84 |
/**
|
|
| 85 |
* Deploy a BPEL business process together with its WSDL.
|
|
| 86 |
*
|
|
| 87 |
* @param bpel
|
|
| 88 |
* BPEL document stream
|
|
| 89 |
* @param wsdl
|
|
| 90 |
* WSDL description stream
|
|
| 91 |
* @return @throws
|
|
| 92 |
* AdminException
|
|
| 93 |
*/
|
|
| 94 | 2 |
public String deploy(InputStream bpel, InputStream wsdl)
|
| 95 |
throws AdminException {
|
|
| 96 | 2 |
return deploy(bpel, wsdl, new ArrayList()); |
| 97 |
} |
|
| 98 |
|
|
| 99 |
/**
|
|
| 100 |
* Deploy a BPEL business process together with its WSDL and one partner
|
|
| 101 |
* WSDL description.
|
|
| 102 |
*
|
|
| 103 |
* @param bpel
|
|
| 104 |
* BPEL document
|
|
| 105 |
* @param wsdl
|
|
| 106 |
* WSDL description
|
|
| 107 |
* @param partnerWSDL
|
|
| 108 |
* partner WSDL description
|
|
| 109 |
* @return @throws
|
|
| 110 |
* AdminException
|
|
| 111 |
*/
|
|
| 112 | 0 |
public String deploy(File bpel, File wsdl, File partnerWSDL)
|
| 113 |
throws AdminException {
|
|
| 114 | 0 |
List list = new ArrayList();
|
| 115 | 0 |
list.add(partnerWSDL); |
| 116 |
|
|
| 117 | 0 |
return deploy(bpel, wsdl, list);
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/**
|
|
| 121 |
* Deploy a BPEL business process together with its WSDL and its partner
|
|
| 122 |
* WSDL descriptions.
|
|
| 123 |
*
|
|
| 124 |
* @param bpel
|
|
| 125 |
* BPEL document
|
|
| 126 |
* @param wsdl
|
|
| 127 |
* WSDL description
|
|
| 128 |
* @param partnerWSDL
|
|
| 129 |
* partner WSDL descriptions
|
|
| 130 |
* @return @throws
|
|
| 131 |
* AdminException
|
|
| 132 |
*/
|
|
| 133 | 0 |
public String deploy(File bpel, File wsdl, List partnerWSDL)
|
| 134 |
throws AdminException {
|
|
| 135 |
|
|
| 136 | 0 |
InputStream bpelIs = null;
|
| 137 | 0 |
InputStream wsdlIs = null;
|
| 138 | 0 |
List list = null;
|
| 139 |
|
|
| 140 | 0 |
try {
|
| 141 | 0 |
bpelIs = new FileInputStream(bpel);
|
| 142 | 0 |
wsdlIs = new FileInputStream(wsdl);
|
| 143 | 0 |
list = new ArrayList();
|
| 144 | 0 |
for (Iterator iter = partnerWSDL.iterator(); iter.hasNext();) {
|
| 145 | 0 |
File file = (File) iter.next(); |
| 146 | 0 |
list.add(new FileInputStream(file));
|
| 147 |
} |
|
| 148 |
} catch (FileNotFoundException e) {
|
|
| 149 | 0 |
throw new AdminException("Unable to locate files", e); |
| 150 |
} |
|
| 151 |
|
|
| 152 | 0 |
return deploy(bpelIs, wsdlIs, list);
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/**
|
|
| 156 |
* Deploys a new BPEL process to bexee.
|
|
| 157 |
*
|
|
| 158 |
* @see #deploy(InputStream, InputStream, List)
|
|
| 159 |
*/
|
|
| 160 | 2 |
public String deploy(InputStream bpel, InputStream wsdl,
|
| 161 |
InputStream partnerWSDL) throws AdminException {
|
|
| 162 |
|
|
| 163 | 2 |
List list = new ArrayList();
|
| 164 | 2 |
list.add(partnerWSDL); |
| 165 |
|
|
| 166 | 2 |
return deploy(bpel, wsdl, list);
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
/**
|
|
| 170 |
* Deploys a new BPEL process to bexee.This method will invoke the
|
|
| 171 |
* <code>Manager</code> web service and pass it the documents.
|
|
| 172 |
*
|
|
| 173 |
* @param bpel
|
|
| 174 |
* @param wsdl
|
|
| 175 |
* @param partnerWSDL
|
|
| 176 |
* @return @throws
|
|
| 177 |
* AdminException
|
|
| 178 |
*/
|
|
| 179 | 4 |
public String deploy(InputStream bpel, InputStream wsdl, List partnerWSDL)
|
| 180 |
throws AdminException {
|
|
| 181 |
|
|
| 182 | 4 |
String[] input = null;
|
| 183 | 4 |
String output = null;
|
| 184 |
|
|
| 185 |
// build call
|
|
| 186 | 4 |
Call call = createCall("deploy");
|
| 187 | 4 |
call.addParameter("input", XMLType.SOAP_ARRAY, ParameterMode.IN);
|
| 188 | 4 |
call.setReturnType(XMLType.XSD_STRING); |
| 189 |
|
|
| 190 |
// build input parameter
|
|
| 191 | 4 |
try {
|
| 192 | 4 |
input = buildInputArray(bpel, wsdl, partnerWSDL); |
| 193 |
} catch (IOException e) {
|
|
| 194 | 0 |
throw new AdminException("Unable to get all input data", e); |
| 195 |
} |
|
| 196 |
|
|
| 197 |
// invoke service
|
|
| 198 | 4 |
try {
|
| 199 | 4 |
output = (String) call.invoke(new Object[] { input });
|
| 200 |
} catch (RemoteException e) {
|
|
| 201 | 0 |
throw new AdminException("Error on invoking Manager deploy()", e); |
| 202 |
} |
|
| 203 |
|
|
| 204 | 4 |
return output;
|
| 205 |
} |
|
| 206 |
|
|
| 207 |
/**
|
|
| 208 |
* Undeploys an existing service
|
|
| 209 |
*
|
|
| 210 |
* @param name
|
|
| 211 |
* the name of the service to be undeployed
|
|
| 212 |
* @return the message from the Manager service
|
|
| 213 |
* @throws AdminException
|
|
| 214 |
* if something went wrong
|
|
| 215 |
* @see {@link Manager}
|
|
| 216 |
*/
|
|
| 217 | 2 |
public String undeploy(String name) throws AdminException { |
| 218 |
|
|
| 219 | 2 |
String[] input = null;
|
| 220 | 2 |
String output = null;
|
| 221 |
|
|
| 222 |
// build call
|
|
| 223 | 2 |
Call call = createCall("undeploy");
|
| 224 | 2 |
call.addParameter("input", XMLType.XSD_STRING, ParameterMode.IN);
|
| 225 | 2 |
call.setReturnType(XMLType.XSD_STRING); |
| 226 |
|
|
| 227 |
// invoke service
|
|
| 228 | 2 |
try {
|
| 229 | 2 |
output = (String) call.invoke(new Object[] { name });
|
| 230 |
} catch (RemoteException e) {
|
|
| 231 | 0 |
throw new AdminException("Error on invoking Manager undeploy()", e); |
| 232 |
} |
|
| 233 |
|
|
| 234 | 2 |
return output;
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/**
|
|
| 238 |
* Create Axis call to service.
|
|
| 239 |
*
|
|
| 240 |
* @return a <code>Call</code> object
|
|
| 241 |
* @throws AdminException
|
|
| 242 |
* if the <code>Call</code> can not be created
|
|
| 243 |
*/
|
|
| 244 | 6 |
protected Call createCall(String operation) throws AdminException { |
| 245 |
|
|
| 246 | 6 |
if (url == null) { |
| 247 | 0 |
throw new AdminException("No url to Manager service provided"); |
| 248 |
} |
|
| 249 |
|
|
| 250 |
// create service and call
|
|
| 251 | 6 |
Service service = new Service();
|
| 252 | 6 |
Call call; |
| 253 | 6 |
try {
|
| 254 | 6 |
call = (Call) service.createCall(); |
| 255 |
} catch (ServiceException e) {
|
|
| 256 | 0 |
throw new AdminException("Unable to create Call", e); |
| 257 |
} |
|
| 258 | 6 |
call.setTargetEndpointAddress(url); |
| 259 | 6 |
call.setOperation(operation); |
| 260 | 6 |
return call;
|
| 261 |
} |
|
| 262 |
|
|
| 263 | 4 |
protected String[] buildInputArray(InputStream bpel, InputStream wsdl,
|
| 264 |
List partnerWSDL) throws IOException {
|
|
| 265 |
|
|
| 266 | 4 |
int length = partnerWSDL == null ? 2 : partnerWSDL.size() + 2; |
| 267 | 4 |
String[] result = new String[length];
|
| 268 |
|
|
| 269 | 4 |
result[0] = getString(bpel); |
| 270 | 4 |
result[1] = getString(wsdl); |
| 271 |
|
|
| 272 | 4 |
for (int i = 0, j = 2; i < partnerWSDL.size(); i++, j++) { |
| 273 | 2 |
InputStream is = (InputStream) partnerWSDL.get(i); |
| 274 | 2 |
result[j] = getString(is); |
| 275 |
} |
|
| 276 |
|
|
| 277 | 4 |
return result;
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
/**
|
|
| 281 |
* Copies an <code>InputStream</code> into a <code>String</code>.
|
|
| 282 |
*
|
|
| 283 |
* @param is
|
|
| 284 |
* the <code>InputStream</code> to be read from.
|
|
| 285 |
* @return a <code>String</code>
|
|
| 286 |
* @throws IOException
|
|
| 287 |
* in case of an I/O problem
|
|
| 288 |
*/
|
|
| 289 | 10 |
protected String getString(InputStream is) throws IOException { |
| 290 |
|
|
| 291 | 10 |
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
| 292 | 10 |
CopyUtils.copy(is, out); |
| 293 | 10 |
return out.toString();
|
| 294 |
} |
|
| 295 |
} |
|
||||||||||